/*
 * Favorites.hpp
 *
 *  Created on: 2014年10月11日
 *      Author: Administrator
 */

#ifndef FAVORITES_HPP_
#define FAVORITES_HPP_

#include <QObject>
#include <bb/data/DataAccessReply>
#include <bb/data/SqlConnection>
#include <bb/cascades/GroupDataModel>

using namespace bb::cascades;

class Favorites: public QObject
{
    // Classes that inherit from QObject must have the Q_OBJECT macro so
    // the meta-object compiler (MOC) can add supporting code to the application.
    Q_OBJECT

    // A property that is used by the list view in QML
    Q_PROPERTY(bb::cascades::DataModel* dataModel READ dataModel CONSTANT)

public:
    Favorites(QObject *parent = 0);

    Q_INVOKABLE QVariantMap createRecord(const QString &title, const QString &url,const QString &content);
    Q_INVOKABLE QVariantMap readRecords();
    Q_INVOKABLE QVariantMap readContentByUrl(const QString &url);
    Q_INVOKABLE bool deleteRecord(const QString &key);
    Q_INVOKABLE bool updateContent(const QString &title, const QString &content);
    Q_INVOKABLE void getAccessCount();
    Q_INVOKABLE bool emptyAccess();

    Q_SIGNALS:
    void contentChanged(const QVariantMap &content);

    Q_SIGNALS:
    void accessCountChanged(const QString &number);

    Q_SIGNALS:
    void created(const bool result);

private:
    // Functions to call upon initialization to setup the model and database
    void initDataModel();

    // To alert the user if something has gone wrong
    void alert(const QString &message);

    // The getter method for the property
    bb::cascades::GroupDataModel* dataModel() const;

    // The data shown by the list view.
    GroupDataModel* m_dataModel;
};

#endif /* FAVORITES_HPP_ */
